package com.renzhichu.app;

import android.app.Application;
import android.content.Context;
import android.support.multidex.MultiDex;
import android.support.multidex.MultiDexApplication;

import com.facebook.react.ReactApplication;

import cn.jpush.reactnativejpush.JPushModule;
import fr.greweb.reactnativeviewshot.RNViewShotPackage;
import org.wonday.orientation.OrientationPackage;

import com.geetest.onelogin.OneLoginHelper;
import com.renzhichu.app.customview.CustomReactPackage;
import com.renzhichu.app.polyv.PolyvLivePackage;
import com.renzhichu.app.polyv.vod.PolyvRNVodPluginManager;
import com.theweflex.react.WeChatPackage;
import com.airbnb.android.react.lottie.LottiePackage;
import com.dylanvann.fastimage.FastImageViewPackage;
import com.tencent.bugly.crashreport.CrashReport;
import com.reactnativecommunity.webview.RNCWebViewPackage;

import cn.jpush.android.api.JPushInterface;
import iyegoroff.RNTextGradient.RNTextGradientPackage;

import com.cmcewen.blurview.BlurViewPackage;

import cn.qiuxiang.react.amap3d.AMap3DPackage;
import cn.qiuxiang.react.geolocation.AMapGeolocationPackage;

import com.BV.LinearGradient.LinearGradientPackage;
import com.horcrux.svg.SvgPackage;
import com.renzhichu.app.onelogin.OneLoginPackage;
import com.swmansion.reanimated.ReanimatedPackage;
import com.reactnativecommunity.asyncstorage.AsyncStoragePackage;

import org.devio.rn.splashscreen.SplashScreenReactPackage;

import com.beefe.picker.PickerViewPackage;
import com.reactnative.ivpusic.imagepicker.PickerPackage;
import com.swmansion.gesturehandler.react.RNGestureHandlerPackage;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;

import cn.jpush.reactnativejpush.JPushPackage;

import java.util.Arrays;
import java.util.List;

import com.easefun.polyv.businesssdk.vodplayer.PolyvVodSDKClient;
import com.easefun.polyv.cloudclass.config.PolyvLiveSDKClient;
import com.easefun.polyv.foundationsdk.log.PolyvCommonLog;

public class MainApplication extends MultiDexApplication implements ReactApplication {
    // 设置为 true 将不会弹出 toast
    private boolean SHUTDOWN_TOAST = true;
    // 设置为 true 将不会打印 log
    private boolean SHUTDOWN_LOG = true;
    private static final String TAG = "PolyvCloudClassApp";
//加密秘钥和加密向量，在点播后台->设置->API接口中获取，用于解密SDK加密串
    //值修改请参考https://github.com/easefun/polyv-android-sdk-demo/wiki/10.%E5%85%B3%E4%BA%8E-SDK%E5%8A%A0%E5%AF%86%E4%B8%B2-%E4%B8%8E-%E7%94%A8%E6%88%B7%E9%85%8D%E7%BD%AE%E4%BF%A1%E6%81%AF%E5%8A%A0%E5%AF%86%E4%BC%A0%E8%BE%93
    /**
     * 加密秘钥
     */
    private String aeskey = "VXtlHmwfS2oYm0CZ";
    /**
     * 加密向量
     */
    private String iv = "2u9gDPKdX6GyQJKU";
    /**
     * SDK加密串，可以在点播后台获取
     */
    private String config = "";
    private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
        @Override
        public boolean getUseDeveloperSupport() {
            return BuildConfig.DEBUG;
        }

    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(),
            new RNViewShotPackage(),
            new OrientationPackage(),
            new WeChatPackage(),
            new LottiePackage(),
            new FastImageViewPackage(),
            new RNCWebViewPackage(),
            new RNTextGradientPackage(),
            new BlurViewPackage(),
            new BlurViewPackage(),
            new AMap3DPackage(),
            new AMapGeolocationPackage(),
            new LinearGradientPackage(),
            new SvgPackage(),
            new ReanimatedPackage(),
            new AsyncStoragePackage(),
            new SplashScreenReactPackage(),
            new PickerViewPackage(),
            new PickerPackage(),
            new RNGestureHandlerPackage(),
            new OneLoginPackage(),
            new PolyvLivePackage(),
            new JPushPackage(SHUTDOWN_TOAST, SHUTDOWN_LOG),   //  <-- 添加 JPushPackage
        new PolyvRNVodPluginManager()  // 新增加的一行！
      );
    }

        @Override
        protected String getJSMainModuleName() {
            return "index";
        }
    };

    @Override
    public ReactNativeHost getReactNativeHost() {
        return mReactNativeHost;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        SoLoader.init(this, /* native exopackage */ false);
        CrashReport.initCrashReport(getApplicationContext(), "6ac82ffd2b", true);
        // Normal app init code...
        PolyvCommonLog.setDebug(true);
        PolyvLiveSDKClient liveSDKClient = PolyvLiveSDKClient.getInstance();
        liveSDKClient.initContext(this);

        PolyvVodSDKClient client = PolyvVodSDKClient.getInstance();
        //使用SDK加密串来配置
        client.setConfig(config, aeskey, iv);
    }

    @Override
    protected void attachBaseContext(Context base){
        super.attachBaseContext(base);
        MultiDex.install(this);
    }

}
